import storageApi from '../../../core/storage/storage';

function problemListController($rootScope, $scope, homeStatsService) {
  'ngInject';

  // 问题列表
  this.getProblem = () => {
    const nowDate = new Date().getTime();
    this.hasProblemNum = false;
    homeStatsService
      .queryProblem({ orgId: $rootScope.orgId || storageApi.get('orgId') })
      .then((res) => {
        if (res.success) {
          this.problemList = res.rows;
          this.problemList = this.problemList.slice(1, 7);
          this.total = res.total;
          if (this.problemList && this.problemList.length > 0) {
            this.hasProblemNum = true;
            this.problemList.forEach((item) => {
              if (item.overdue) {
                item.redColor = { color: '#fd5757' };
              }
            });
          } else {
            this.hasProblemNum = false;
          }
        }
      });
  };

  this.getProblem();
}

export default problemListController;
